<?php
	/**
	 * Elgg product - view all
	 * 
	 * @package Elgg SocialCommerce
	 * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2
	 * @author Cubet Technologies
	 * @copyright Cubet Technologies 2009-2010
	 * @link http://elgghub.com/
 	**/
	 
	global $CONFIG;
	// Load Elgg engine
		require_once(dirname(dirname(dirname(__FILE__))) . "/engine/start.php");
		
	// Get the current page's owner
	/*
		$page_owner = page_owner_entity();
		if ($page_owner === false || is_null($page_owner)) {
			$page_owner = $_SESSION['user'];
			set_page_owner($_SESSION['guid']);
		}
		*/

	//set stores title
		$title = elgg_view_title(elgg_echo('stores:all:products'));
		
	// Get objects
		set_context('allproducts');
		$search_viewtype = get_input('search_viewtype');
		set_input('search_viewtype','box');						// tbc setting view type to new type Box
		$search_viewtype = get_input('search_viewtype');		// tbc  getting view type
		//echo('/search_viewtype_:'.$search_viewtype.'_/');		//----------------------
		if($search_viewtype == 'gallery'){
			$limit = 20;
		}else{
			$limit = 12;
		}
		$view = get_input('view');
		//echo('/view:'.$view.'_/');				//----------------------
//		$snumber = 146;

		//$nnn = $page_owner->guid;				//----------------------

		$days = get_days_previous_days($CONFIG->expiry_time);
		if (isloggedin()) {
			$filter = get_input("filter");
			//echo('/filter:'.$filter.'_/');			//----------------------
			if(!$filter)
				$filter = "active";
			switch($filter){
				case "active":

					$options = array(	'metadata_name_value_pairs'	=>	array('status' => 1),
										'types'				=>	"object",
										'subtypes'			=>	"stores",
										'limit'				=> $limit,
										'created_time_lower' => $days,
										
									);
					//echo($options['owner_guid']);
					//echo("/page_owner:".$nnn);
					//print_r($options);
					$area2 = elgg_list_entities_from_metadata($options);
						

				break;
				case "deleted":

					$options = array(	'metadata_name_value_pairs'	=>	array('status' => 0),
										'types'				=>	"object",
										'subtypes'			=>	"stores",
										'limit'				=> $limit,
										
									);
					$area2 = elgg_list_entities_from_metadata($options);

				break;
			}
			if(empty($area2)){
				$area2 = elgg_echo('product:null');
			}
			if(empty($area2)){
				$area2 = "<div style=\"padding:10px;\">".elgg_echo('no:data')."</div>";	
			}
			if($view != 'rss'){

				//$area2 = elgg_view("{$CONFIG->pluginname}/product_tab_view",array('base_view' => $area2, "filter" => $filter));
				//echo($area2);
			}
		}else{
			//Depricated function replace
			$options = array(	'metadata_name_value_pairs'	=>	array('status' => 1),
								'types'				=>	"object",
								'subtypes'			=>	"stores",
								'limit'				=> $limit,
								'created_time_lower' => $days,
							);
			$area2 = elgg_list_entities_from_metadata($options);
			//$area2 = list_entities_from_metadata('status',1,"object","stores",0,$limit);
			if(empty($area2)){
				$area2 = elgg_echo('product:null');
			}
		}
		
		if($view != 'rss'){
			$area2 = <<<EOF
				{$title}
				<div class="contentWrapper stores">
					 {$area2}
				</div>
EOF;
		}		// css file line 290
		
	//echo "~~~".add_to_river('river/object/stores/create','create',91,2);
		set_context('stores');
	// These for left side menu
		$area1 .= gettags();
		

		//$area1 .= get_storestype_cloud(page_owner());
	// Create a layout
		$body = elgg_view_layout('two_column_left_sidebar', $area1, $area2);
	
	// Finally draw the page
		page_draw(sprintf(elgg_echo("stores:all:products"),page_owner_entity()->name), $body);

	
?>
